class Tag < ActiveRecord::Base
  
  SIZE   = "file size in bytes"
  JPG    = "image/jpg"
  PNG    = "image/png"
  GIF    = "image/gif"
  WIDTH  = "width in pixels"
  HEIGHT = "height in pixels"
  # Aspect ratio ommited for now; since dichotomies are no longer allowed.. how can you easily specify this value in a search instead of optimizing for it?
  AREA   = "Area in pixels"
  # compression quality / power skipped since we lost dichotomies
  # Skipping "number of unique colors" and "colorfulness" for brevity


  has_many :votes, :dependent => :destroy
  has_many :image_facts, :through => :votes
  validates_uniqueness_of :tagname
    
  def self.text1
    find(:all).each { |t| puts "%5d %s" % [t.id, t.tagname] }
    nil
  end
  
  def self.invoke(val, options=nil)
    options ||= {}
    options[:create] ||= 'no'
    if(val.to_i>0)
      tag = Tag.find val
    else
      val.downcase!
      if(options[:create]=='yes')
        tag = Tag.find_or_create_by_tagname val
      else
        tag = Tag.find_by_tagname(val) or raise "Could not politely find tag '#{val}'"
      end
    end
    
    tag
  end
end
